package hxy.scan.server.controller;

import hxy.scan.server.dao.mapper.FruitMapper;
import hxy.scan.server.dao.model.CustomerModel;
import hxy.scan.server.dao.model.FruitModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
public class FruitController {

    @Resource
    FruitMapper fruitMapper;


    @GetMapping("/fruit-create")
    public int create(FruitModel fruitEntity) {

        String name = fruitEntity.getName();

        if (name==null){
            return 0;
        }

        return fruitMapper.insert(fruitEntity);
    }


    @GetMapping("/fruit-list")
    public List<FruitModel> list() {

        return fruitMapper.selectList(null);
    }

    @GetMapping("/fruit-delete")
    public int delete(int id) {
        return fruitMapper.deleteById(id);
    }



    @GetMapping("/fruit-update")
    public int update(FruitModel fruitEntitle) {
        return fruitMapper.updateById(fruitEntitle);
    }


    @GetMapping("/hashmap")
    public HashMap hashMap(){
        HashMap<String,Object> hashMap = new HashMap();


        CustomerModel value = new CustomerModel();
        hashMap.put("name", value);

        hashMap.put("安徽","三元/斤");
        hashMap.put("安徽1","三元/斤");
        hashMap.put("安庆","三元/斤");
        hashMap.put("芜湖","三元/斤");
        hashMap.put("合肥","三元/斤");
        hashMap.put("安徽21","三元/斤");
        hashMap.put("安徽231","三元/斤");
        hashMap.put("安徽22","三元/斤");
        hashMap.put("安徽23","三元/斤");
        hashMap.put("安徽42","三元/斤");
        hashMap.put("安徽2","三元/斤");
        hashMap.put("大豆" ,"5元/斤");
        hashMap.put("玉米" ,"8元/斤");
        return hashMap;
    }

}

